<?php

namespace App\Model;

use App\BaseModel;

class UserSearchRecords extends BaseModel
{
    protected $table = "t_user_search_records";


    public static function saveRecord($user_id,$keyword,$result)
    {
        $m = new UserSearchRecords();
        $m->user_id = $user_id;
        $m->keyword = $keyword;
        $m->result = $result;
        return $m->save();
    }

    public static function getSearchResult($keyword)
    {
        $r = UserSearchRecords::where('keyword','=',$keyword)
            ->where('created_at','<=',date('Y-m-d H:i:s',time()+180))
            ->orderBy('created_at','desc')
            ->first();
        if ($r&&$r->result){
            return json_decode($r->result,true);
        }
        return false;
    }

}
